package com.chefu.carowner.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chefu.carowner.pojo.CarUser;
import com.chefu.carowner.service.CarUserService;
import com.chefu.common.pojo.PageResult;
import com.chefu.common.pojo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author goodgoodstudy
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/carOwner")
public class CarUserController {

    @Autowired
    CarUserService carUserService;

    /**
     * 查询车主列表
     */
    @GetMapping("/{pageNo}/{pageSize}")
    public R findUserByPage(@PathVariable("pageNo") Long pageNo,
                        @PathVariable("pageSize") Long pageSize,
                        @RequestParam(required = false) String name,
                        @RequestParam(required = false)String phone,
                        @RequestParam(required = false) Integer status){
        PageResult<CarUser> page = carUserService.findUserByPage(pageNo, pageSize, name, phone, status);
        return R.ok().data("page", page);
    }

    /**
     * 发送手机验证码
     */
    @PostMapping("/code")
    public R sendVerifyCode(@RequestParam("phone") String phone){
        carUserService.sendVerifyCode(phone);
        return R.ok();
    }

    /**
     * 车主登陆
     */
    @PostMapping("/login")
    public R login(@RequestParam String phone, @RequestParam String code){
//        carUserService.login(phone, code);
        return R.ok();
    }

    /**
     * 修改车主信息
     */
    @PutMapping
    public R update(@RequestBody CarUser carUser){
        carUserService.updateCarOwner(carUser);
        return R.ok();
    }

    /**
     * 修改密码
     */
    @PutMapping("/modifyPwd")
    public R modifyPwd(@RequestParam String oldPwd, @RequestParam String newPwd){
        carUserService.modifyPwd(oldPwd, newPwd);
        return R.ok();
    }

    /**
     * 锁定车主
     */
    @PutMapping("/lock")
    public R updateStatus(@RequestParam Long uid, @RequestParam Integer status){
        CarUser user = new CarUser();
        user.setCuId(uid);
        user.setStatus(status);
        carUserService.updateById(user);
        return R.ok();
    }

}

